package jp.millibit.util
{
	import flash.utils.Dictionary;

	import jp.millibit.core.notnull;

	public dynamic class WeakReference
	{

		private var _ref:Dictionary;

		public function WeakReference(object:Object, watcher:GCWatcher = null)
		{
			notnull(object, "object");

			_ref = new Dictionary(true);
			_ref[object] = null;

			if (watcher != null)
			{
				watcher.register(this);
			}
		}

		public function getObject():Object
		{
			for (var object:Object in _ref)
			{
				return object;
			}

			return null;
		}
	}
}
